Implementing Fuzzy Logic on ESP32 for Weight Anomaly Detection in Smart Shelf Systems
Detecting abnormal item removal in automated storage systems requires more than simple threshold comparison. In the Smart Shoes Shelves System, a fuzzy logic-based weight monitoring algorithm was implemented on ESP32 to improve anomaly detection accuracy.

Unlike conventional systems that trigger alarms when weight drops below a fixed limit, this design evaluates both weight deviation and rate of change to reduce false positives caused by vibration, gradual handling, or sensor noise.
System Architecture Overview

The hardware consists of:
- ESP32 microcontroller
- Load cell sensor
- HX711 24-bit ADC amplifier
- LCD 16x2 I2C
- Buzzer alarm
- Firebase integration
The board layout and component placement are shown in the Board Details section, highlighting integration between sensor input, LCD interface, and ESP32 core processing.

The system continuously measures weight (Present Value / PV) and compares it to a stored setpoint (SP).
Mathematical Foundation
The fuzzy system is based on two input variables:
Error:

Delta Error:

Where:
- SP = Setpoint weight
- PV = Current measured weight
- ΔE = Rate of weight change
This allows detection of sudden removal events versus gradual user interaction.
Membership Function Design & Rule Base Implementation
Error membership sets:
- NB (Negative Big)
- NS (Negative Small)
- ZO (Zero)
- PS (Positive Small)
- PB (Positive Big)
Delta Error membership sets:
- NB
- NS
- ZO
- PS
- PB
The interval resolution used:
- Error interval = 0.5
- Delta error interval = 0.2
Triangular membership functions were used for smooth transitions between states.
This prevents rigid decision boundaries.

The rule evaluation matrix defines output behavior:
Output categories:
- Normal
- Warning + Notification
- Alarm & Notifications
Example rule:
IF Error = NB
AND Delta Error = NB
THEN Output = Alarm & Notification
This rule detects sudden significant weight removal.
Defuzzification is implemented using a singleton method with output values:
- 0 → Normal
- -1 → Warning
- -2 → Alarm
Firmware Implementation on ESP32

Implementation steps:
- Read HX711 value
- Apply filtering (moving average)
- Compute error and delta error
- Calculate membership degrees
- Evaluate fuzzy rules
- Compute weighted output
- Trigger buzzer and Firebase alert
The calibration process ensures accurate weight measurement before fuzzy evaluation begins.
System Behavior
When a correct item is removed through the application interface, the setpoint is updated dynamically.

However, if weight changes without proper command sequence, the fuzzy engine evaluates the anomaly and activates the alarm state.
This dynamic adaptation significantly reduces false alarms compared to static threshold methods.
Engineering Insight
The integration of fuzzy logic into an embedded IoT platform demonstrates how lightweight AI techniques can enhance reliability in real-world systems.
Instead of binary logic, the system operates using graded decision-making, making it more robust against:
- Mechanical vibration
- Sensor drift
- Gradual load changes
- Minor noise fluctuation
This approach bridges classical embedded programming with intelligent decision systems, suitable for smart inventory, anti-theft storage, and automated monitoring environments.
#AI# #Fuzzy# #Embedded#
Sign In Or Register Comment after
No comments yet. Be the first to comment!